const app = getApp()
const http = require('../../../utils/http.js')

Component({
  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    amount: 0,
    integral: 0,
    couponSize: 0,
    userInfo: null,
    hasUserInfo: false,
    shuoming: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    checkAuth() {
      if (!app.globalData.userInfo.mobile) {
        wx.navigateTo({
          url: '/pages/auth/auth'
        })
      }else {
        this.setData({
          userInfo: app.globalData.userInfo,
          hasUserInfo: true
        })
      }
    }
  },

  lifetimes: {
    attached: function () {
      if (app.globalData.customerName == '煌华新纪元') {
        this.setData({
          shuoming: true
        })
      }
      this.checkAuth()
      this.setData({
        customerName: app.globalData.customerName
      })
      if (this.data.hasUserInfo) {
        http.get('/api/user/selectMember').then(res => {
          if (res.code == 200) {
            this.setData({
              amount: res.result.amount,
              integral: res.result.integral,
              couponSize: res.result.couponList.length
            })
          }
        })
      }

    },
  },

  pageLifetimes: {
    show: function() {
      this.checkAuth()
    },
  }

})
